{% extends "base.html" %}

{% block title %}服务器查询{% endblock %}
{% block navbar %}
<section class="content-header">
    <h1>服务器查询</h1>
    <ol class="breadcrumb">
        <li><i class="fa fa-dashboard"></i> 当前位置</li>
        <li class="active">服务器管理</li>
        <li class="active">服务器查询</li>
    </ol>
</section>
{% endblock %}

{% block content %}
<div class="box box-primary">
    <div class="box-header with-border">
        {% include 'message.html' %}
    </div>

    <div class="box-body">
        {% if form%}
        <table class="table table-bordered">
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>IP</th>
                <th>端口</th>
                <th>用户名</th>
                <th>终端</th>
                <th>编辑</th>
                <th>删除</th>
            </tr>
            {% for row in form.content %}
            <tr>
                <td>{{row.id}}</td>
                <td>{{row.name}}</td>
                <td>{{row.ip}}</td>
                <td>{{row.port}}</td>
                <td>{{row.user}}</td>
                <td><a class='fa fa-lg fa-television text-light-blue'
                    href='{{ url_for("main.get_term", id=row.id) }}' target="_blank"></a></td>
                <td><a class='fa fa-lg fa-edit text-light-blue'
                    href='{{ url_for("main.serveredit", id=row.id) }}'></a></td>
                <td><a class='fa fa-lg fa-warning text-red' href='?action=del&id={{row.id}}'></a></td>
            </tr>
            {% endfor %}
        </table>
        {% endif %}
    </div>

    <div class="box-footer clearfix">
        {% if form%}
        <ul class="pagination pagination-sm no-margin pull-right">
            <li><a href="#">&laquo;</a></li>
            {% for i in range(1, form.total_page+ 1) %}
            {% if i == form.page %}
            <li><a href="?page={{i}}"><b>{{i}}</b></a></li>
            {% else %}
            <li><a href="?page={{i}}">{{i}}</a></li>
            {% endif %}
            {% endfor %}
            <li><a href="#">&raquo;</a></li>
        </ul>
        {% endif %}
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    function initPage() {
        slide_value = $(".slider").val() == "" ? 50 : parseInt($(".slider").val());
        $(".slider").slider({
            id: "blue",
            max: 100,
            value: slide_value
        });

        $('.status').bootstrapSwitch();
        $(".status").on("switchChange.bootstrapSwitch", function (event, state) {
            switchStatus($(this).data("id"), state, this);
        });
        $('.fa-start').on("click", function () {
            $.post('/pifrpc', {
                'mac': $(this).data("mac")
            }, function (res) {
                if (res["result"] == 0) {
                    alert("操作成功")
                }
                else {
                    alert(res["msg"])
                }
            });
        });
    }
    function switchStatus(id, status, switchBox) {
        restTemplate("PUT", "/notifies/" + id + "/status/" + status, null, function () {
            $($(switchBox)).bootstrapSwitch("state", status);
        });
    }
</script>
{% endblock %}